package com.joolun.mall.util.excel;

import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.Row;

public class SingleRowHeightHandler implements RowWriteHandler {
    private final int targetRowIndex; // 目标行索引（从0开始）
    private final float rowHeight;    // 行高（单位：磅）

    public SingleRowHeightHandler(int targetRowIndex, float rowHeight) {
        this.targetRowIndex = targetRowIndex;
        this.rowHeight = rowHeight;
    }
//
//    @Override
//    public void afterRowCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer relativeRowIndex, Boolean isHead) {
//        // 仅在目标行索引匹配时设置行高
//        if (relativeRowIndex == targetRowIndex) {
//            row.setHeightInPoints(rowHeight); // 关键：每次创建行时动态设置
//        }
//    }

    @Override
    public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer relativeRowIndex, Boolean isHead) {
        // 仅在目标行索引匹配时设置行高
        if (relativeRowIndex == targetRowIndex) {
            row.setHeightInPoints(rowHeight); // 关键：每次创建行时动态设置
        }else{
            row.setHeightInPoints(20);
        }
    }


}